package cn.wxl.plugindemo

import java.io.File

/**
 * Author:Wang Xiaolong, 2022/1/7 18:05
 */
object AddCodeUtil {

    private const val fileName = "Demo2.java"

    fun addCode(projectDir: String?, extension: SrcExt?) {
        if (projectDir == null || extension == null) return
        var packageName = extension.packageName
        if (packageName == null) packageName = ""
        val packageDir = packageName.replace(".", "/")
        LogUtil.error("packageDir:$packageDir")
        val dir = File(projectDir + "/" + extension.sourceDir + "/" + packageDir)
        if (!dir.exists()) dir.mkdirs()
        val cf = File(dir, fileName)
        LogUtil.error("Demo:$cf")
        cf.createNewFile()
        cf.writeText("package $packageName;\npublic class Demo2 {\npublic String test() { return \"wxl888\"; }\n}\n")
    }
}